#ifndef _RECTANGLESTLLISTH_H_
#define _RECTANGLESTLLISTH_H_


#include <list>
#include <iostream>
using namespace std;

#include "rectangleH.h"

class RectangleSTLList
{
	list<Rectangl *> L; 
	int size;

public:

	RectangleSTLList()
	{
		size = 0;
	}

	~RectangleSTLList()
	{
		list<Rectangl *>::iterator i;

		for(i=L.begin(); i != L.end(); ++i)
			delete (*i);
	}

	void addNewRectangeToHead(Rectangl * r) // Add to head
	{
		L.push_front(r);
	}

	void addNewRectangeToTail(Rectangl * r) // Add to tail
	{
		L.push_back(r);
	}

	void DrawList(int x) // Draw all list
	{
		if(L.empty()){
			cerr << "Sorry, The List is empty"; 
			return;
		}
		   
		list<Rectangl *>::iterator i;

		for(i=L.begin(); i != L.end(); ++i)
			(*i)->goAndDrawRectangle(x);
	}

	bool isPointExistInList(int x, int y, Rectangl ** recOut) // checks - is point from user exists in list of rectangles ?
	{

		list<Rectangl *>::iterator i;

		for(i=L.begin(); i != L.end(); ++i)
		{
			if((*i)->pointInRectangle(x,y))
			{ 
			   *recOut = (*i);
			   return true;
			}
		}

		return false;
	}

	bool removeFromList(Rectangl * r) // remove from list
	{
		list<Rectangl *>::iterator i;
		for(i=L.begin(); i != L.end(); ++i)
		{
			if((*i) == r)
			{
				L.remove(r);
				return true;
			}
		}
	
		return false;
	}

	void BringToFront(Rectangl * r)
	{
		L.remove(r);
		L.push_back(r);
	}

	void BringToBack(Rectangl * r)
	{
		L.remove(r);
		L.push_front(r);
	}

	int SizeOfList()
	{
		return L.size();
	}

};


#endif
